package com;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author wjrsoft
 * @since 2023.04.15
 */
@Component
@Order(value = 1)
public class SpringBootAfterRunner implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(SpringBootAfterRunner.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("启动完成后，开始执行方法");
        redisTemplate.boundValueOps("StringKey").set("StringValue");
        redisTemplate.boundValueOps("StringKey").set("StringValue",1, TimeUnit.MINUTES);
        String str1 = (String) redisTemplate.boundValueOps("StringKey").get();
        System.out.println(str1);
        refush();
    }

    public void refush() {
        ScheduledExecutorService timer = Executors.newScheduledThreadPool(1);
        timer.scheduleWithFixedDelay(() -> {
            logger.info("定时器");
        }, 10, 3600, TimeUnit.SECONDS);
    }

}